<template>
  <div class="login">
    <div class="login-bg">
      <div class="login-container">
        <div class="login-box">
          <img src="../../../assets/image/logo.png" class="logo">
          <div class="login-title">欢迎使用旅游信息推荐系统</div>
          <div class="login-subtitle">
            珍藏每一刻的美好，旅行让生活变得更加有意义！
          </div>
          <div class="form-group">
            <el-input 
              prefix-icon="el-icon-user" 
              v-model="loginAccount" 
              placeholder="请输入登录账号">
            </el-input>
          </div>
          <div class="form-group">
            <el-input 
              prefix-icon="el-icon-lock" 
              type="password" 
              v-model="password" 
              placeholder="请输入用户密码"
              @keyup.enter.native="login">
            </el-input>
          </div>
          <div class="login-btn" @click="login">
            登 录
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {login,getUser} from '../../../api/api'
  export default {
    data() {
      return{
        loginAccount: '',
        password: ''
      }
    },
    methods: {
        login() {
            if(!this.loginAccount) {
                this.$message({
                    message: '请输入用户名',
                    type: 'warning'
                });
                return;
            }
            if(!this.password) {
                this.$message({
                    message: '请输入密码',
                    type: 'warning'
                });
                return;
            }
            var params = {
                loginAccount: this.loginAccount,
                password: this.password
            }
            login(params).then(res => {
                if(res.code == 1000) {
                    this.$message({
                        message: '登陆成功',
                        type: 'success'
                    });
                    var that = this
                    var token = res.data.token
                    this.$store.commit('user/setToken', token)
                    this.getUserInfo()
                    setTimeout(function() {
                        const redirect = that.$route.query.redirect || '/index'
                        that.$router.push(redirect)
                    },500)
                } else {
                    this.$message.error(res.message);
                }
            })
        },
        getUserInfo() {
            getUser().then(res => {
                if(res.code == 1000) {
                    this.$store.commit('user/setUser', JSON.stringify(res.data))
                }
            })
        },
    },
    created() {

    },
    mounted() {

    }
 }
</script>

<style scoped>
.login {
    width: 100%;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.login-bg {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background: linear-gradient(rgba(255, 255, 255, 0.3), rgba(255, 236, 210, 0.3)),
                url('https://images.unsplash.com/photo-1507525428034-b723cf961d3e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2346&q=80') center/cover no-repeat;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-container {
    width: 100%;
    max-width: 450px;
    padding: 0 20px;
}

.login-box {
    width: 100%;
    padding: 40px;
    background: linear-gradient(135deg, 
        rgba(255, 236, 210, 0.95), 
        rgba(255, 223, 187, 0.9),
        rgba(255, 255, 255, 0.85));
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.logo {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    border-radius: 50%;
    padding: 10px;
    background: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.login-title {
    font-size: 24px;
    font-weight: bold;
    color: #2C3E50;
    margin-bottom: 15px;
    text-align: center;
}

.login-subtitle {
    font-size: 16px;
    color: #34495E;
    margin-bottom: 30px;
    text-align: center;
    letter-spacing: 1px;
}

.form-group {
    width: 100%;
    margin-bottom: 20px;
}

.el-input {
    width: 100%;
}

.el-input :deep(.el-input__inner) {
    height: 45px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    transition: all 0.3s ease;
}

.el-input :deep(.el-input__inner):focus {
    border-color: #FF9966;
    box-shadow: 0 0 0 2px rgba(255, 153, 102, 0.2);
}

.el-input :deep(.el-input__prefix) {
    color: #FF9966;
}

.login-btn {
    width: 100%;
    height: 45px;
    background: linear-gradient(135deg, #FF9966, #FF5E62);
    color: white;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 2px;
    margin-top: 10px;
    transition: all 0.3s ease;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 94, 98, 0.3);
    background: linear-gradient(135deg, #FF8B60, #FF4B50);
}

@media screen and (max-width: 768px) {
    .login-container {
        padding: 0 15px;
    }
    
    .login-box {
        padding: 30px 20px;
    }
}
</style>
